package com.Jstation;

import java.util.Observable;

/**
 * @author SnowmanAndBee
 * @version <version>
 * 使用内置的主题类Observable，用类是不好的，限制了子类的继承
 * 不要依赖观察者通知的顺序
 * @date 2021/12/14 - 20:34
 */
public class WeatherData extends Observable {
    private double temperature;
    private double humidity;
    private double pressure;

    public WeatherData(){}

    /**
     * setChanged来指示状态已经改变
     * notifyObservers可以传送数据对象，也可以不传送，采用“拉”的做法
     */
    private void measurementsChanged() {
        setChanged();
        notifyObservers();
    }

    public void setMeasurements(double temperature, double humidity, double pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        measurementsChanged();
    }

    public double getTemperature() {
        return temperature;
    }

    public double getHumidity() {
        return humidity;
    }

    public double getPressure() {
        return pressure;
    }
}
